<?php
namespace app\admin\controller;

use app\common\model\Groups;
use think\Db;
/**
 * 工人管理
 *
 * @author LCY <409028735@qq.com>
 */
class Workers extends Backend
{
    /**
     * 列表页
     *
     * @return void
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $page, $offset, $limit) = $this->buildSearchParams($this->searchFields);
            $rows = Db::name($this->tableName)->alias('a')->leftJoin('__GROUPS__ b','a.groups_id=b.id')->where($where)->field('a.*,b.groups_name')->order('a.'.$sort, $order)->paginate([
                'list_rows' => $limit,
                'page' => $page,
            ]);
            $data = [
                'total' => $rows->total(),
                'rows' => $rows->items(),
            ];
            return json($data);
        }
        $this->assign('groups', Groups::getAllGroups());
        return $this->fetch();
    }

    public function add(){
        if($this->request->isGet()) {
            $this->assign('groups', Groups::getAllGroups());
        }
        return parent::add();
    }

    public function edit(){
        if($this->request->isGet()) {
            $this->assign('groups', Groups::getAllGroups());
        }
        return parent::edit();
    }

   
}